import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const whileUrl = [
    'lowcode',
    'visually',
    'communicate',
]

export const judgeSub = (name?: string) => {
    console.log(123231, name)
    // return whileUrl.some(item => path.startsWith(item))
    return name && whileUrl.includes(name)
}

const homeRoutes: Array<RouteRecordRaw> = [
    {
        path: 'lowcode:afterUser(.*)',
        name: 'lowcode',
        component: () => import('@/views/home.vue'),
    },{
        // 匹配visually开头的路由
        path: 'visually:afterUser(.*)',
        name: 'visually',
        component: () => import('@/views/home.vue'),
    },{
        // 匹配communicate开头的路由
        path: 'communicate:afterUser(.*)',
        name: 'communicate',
        component: () => import('@/views/home.vue'),
    }
]

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'layout',
        component: () => import('@/layout/index.vue'),
        children: [
            {
                path: '',
                name: 'home',
                component: () => import('@/views/home.vue'),
            },
            ...homeRoutes
        ]
    }, {
        path: '/login',
        name: 'login',
        component: () => import('@/views/entryLogin/index.vue'),
    }, {
        //任意路由
        path: '/:pathMatch(.*)*',
        component: () => import('@/views/404/index.vue'),
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

export default router
